package com.demo.java.OD401_450.OD428;

import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【结对编程(C&D卷)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146311580
 */
public class OdMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();  // 输入数组大小
        int[] level = new int[n];

        // 输入数组元素
        for (int i = 0; i < n; i++) {
            level[i] = scanner.nextInt();
        }

        // 统计左侧符合条件的元素个数
        int[] countLeft = new int[n];
        for (int i = 0; i < n; i++) {
            int count = 0;
            for (int j = 0; j < i; j++) {
                if (level[j] < level[i]) {
                    count++;
                }
            }
            countLeft[i] = count;
        }

        // 统计右侧符合条件的元素个数
        int[] countRight = new int[n];
        for (int i = n - 1; i >= 0; i--) {
            int count = 0;
            for (int j = n - 1; j > i; j--) {
                if (level[j] > level[i]) {
                    count++;
                }
            }
            countRight[i] = count;
        }

        // 计算符合条件的三元组数
        long result = 0;
        for (int i = 0; i < n; i++) {
            result += (long) countLeft[i] * countRight[i];
        }

        System.out.println(result);  // 输出结果
    }
}
